package com.turing.post.report.util;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;

import com.turing.post.util.PCPSUtil;

/**
 * 销售机构资金日结表
 * 
 * @author 李治
 * 
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "SaleCapitalDaySettlement")
@IdClass(SaleCapitalDaySettlement.class)
public class SaleCapitalDaySettlement implements Serializable {
	/**
	 * 销售机构号
	 */
	private String saleBranchNo;
	/**
	 * 日期
	 */
	private Date tranDate;
	/**
	 * 上期信用度
	 */
	private BigInteger lastCredit;
	/**
	 * 上期现金
	 */
	private BigInteger lastCash;
	/**
	 * 现金存入
	 */
	private BigInteger cashDeposit;
	/**
	 * 现金支出
	 */
	private BigInteger cashWithdraw;
	/**
	 * 信用度缴存
	 */
	private BigInteger creditDeposit;
	/**
	 * 信用度支出
	 */
	private BigInteger creditWithdraw;
	/**
	 * 当前信用度
	 */
	private BigInteger credit;
	/**
	 * 现金余额
	 */
	private BigInteger cash;

	public SaleCapitalDaySettlement() {
		super();
	}

	@Id
	@Column(name = "SALEBRANCHNO", nullable = false)
	public String getSaleBranchNo() {
		return saleBranchNo;
	}

	public void setSaleBranchNo(String saleBranchNo) {
		this.saleBranchNo = saleBranchNo;
	}

	@Id
	@Column(name = "TRANDATE", nullable = false)
	public Date getTranDate() {
		return tranDate;
	}

	public void setTranDate(Date tranDate) {
		this.tranDate = tranDate;
	}

	@Column(name = "LASTCREDIT", nullable = false)
	public BigInteger getLastCredit() {
		return lastCredit;
	}

	public void setLastCredit(BigInteger lastCredit) {
		this.lastCredit = lastCredit;
	}

	@Column(name = "LASTCASH", nullable = false)
	public BigInteger getLastCash() {
		return lastCash;
	}

	public void setLastCash(BigInteger lastCash) {
		this.lastCash = lastCash;
	}

	@Column(name = "CASHDEPOSIT", nullable = false)
	public BigInteger getCashDeposit() {
		return cashDeposit;
	}

	public void setCashDeposit(BigInteger cashDeposit) {
		this.cashDeposit = cashDeposit;
	}

	@Column(name = "CASHWITHDRAW", nullable = false)
	public BigInteger getCashWithdraw() {
		return cashWithdraw;
	}

	public void setCashWithdraw(BigInteger cashWithdraw) {
		this.cashWithdraw = cashWithdraw;
	}

	@Column(name = "CREDITDEPOSIT", nullable = false)
	public BigInteger getCreditDeposit() {
		return creditDeposit;
	}

	public void setCreditDeposit(BigInteger creditDeposit) {
		this.creditDeposit = creditDeposit;
	}

	@Column(name = "CREDITWITHDRAW", nullable = false)
	public BigInteger getCreditWithdraw() {
		return creditWithdraw;
	}

	public void setCreditWithdraw(BigInteger creditWithdraw) {
		this.creditWithdraw = creditWithdraw;
	}

	@Column(name = "CREDIT", nullable = false)
	public BigInteger getCredit() {
		return credit;
	}

	public void setCredit(BigInteger credit) {
		this.credit = credit;
	}

	@Column(name = "CASH", nullable = false)
	public BigInteger getCash() {
		return cash;
	}

	public void setCash(BigInteger cash) {
		this.cash = cash;
	}

	public void reCalcToday() {
		BigInteger bal = getLastCredit();
		bal = bal.add(getCreditDeposit());
		bal = bal.subtract(getCreditWithdraw());
		setCredit(bal);

		bal = getLastCash();
		bal = bal.add(getCashDeposit());
		bal = bal.subtract(getCashWithdraw());
		setCash(bal);
	}

	@Override
	public int hashCode() {
		return PCPSUtil.getObjectListHashCode(new Object[] { getSaleBranchNo(),
				getTranDate() });
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof SaleCapitalDaySettlement))
			return false;

		SaleCapitalDaySettlement other = (SaleCapitalDaySettlement) obj;

		if (!PCPSUtil.compareObject(this.getTranDate(), other.getTranDate()))
			return false;

		return PCPSUtil.compareObject(this.getSaleBranchNo(), other
				.getSaleBranchNo());
	}
}
